package com.ycode.bang.anbang.utils;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ycode.bang.anbang.R;
/**
 * Created by wu on 2015/9/10.
 */
public class DialogProgress {

    Context mContext;
    Dialog dialog;
    Activity activity;

    TextView message;
    public DialogProgress(Context mContext) {
        this.mContext = mContext;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public void showlistviewdialog(String value) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.fragment_progress_dialog, null);
        message = (TextView) view.findViewById(R.id.progressDialog_message);

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext, android.R.style.Theme_Holo_Light_Dialog);
        dialog = builder.create();

        dialog.getWindow().setBackgroundDrawableResource(R.drawable.transparent_bg);
//        dialog.getWindow().setGravity(Gravity.BOTTOM);
        dialog.setCancelable(true);//返回键

        dialog.setCanceledOnTouchOutside(false);//空白区域,dialog不消失
        dialog.show();

//        WindowManager windowManager = activity.getWindowManager();
//        Display display = windowManager.getDefaultDisplay();
//        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
//        lp.width = (int) ((display.getWidth()) / 1.5); //设置宽度
//        dialog.getWindow().setAttributes(lp);

        dialog.setContentView(view);

        message.setText(value);
    }

    public void closedialog(){
        if(dialog!=null){
            dialog.dismiss();
        }
    }

    public void altermessage(String value){
        message.setText(value);
    }
}
